import torch
import torch.nn as nn
from torchvision import models
import torch.nn.functional as F

model_path = './vgg16-397923af.pth'
vgg16 = models.vgg16(pretrained=False)
vgg16.load_state_dict(torch.load(model_path, 'cpu'))
# 或：
# vgg16 = models.vgg16(pretrained=True)
# 获取VGG16的特征提取层
vgg = vgg16.features
class SiameseNetwork(nn.Module):
    def __init__(self, input_shape):
        super(SiameseNetwork, self).__init__()
        self.vgg = vgg
    def forward_once(self, x):
        output = self.vgg(x)
        output = torch.flatten(output, 1) #向量展平
    def forward(self, input1, input2):
        output1 = self.forward_once(input1)
        output2 = self.forward_once(input2) 
